<?php

namespace App\Admin\Controllers;

use App\Admin\Forms\Config\Level;
use App\Admin\Repositories\Good;
use App\Models\Category;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class GoodController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Good(), function (Grid $grid) {
            $grid->model()->with(['category']);
            $grid->column('id')->sortable();
            $grid->column('image')->image(null,50,50);
            $grid->column('name')->limit(15);
            $grid->column('category.name','商品分类');
            $grid->column('price');
            $grid->column('status')->using(['上架','下架'])->label(['info','default']);
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->like('name');
                $filter->like('category.name','商品分类');
            });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Good(), function (Form $form) {
            $form->tab("基本信息",function (Form $form){
                $form->column(5,function (Form $form){
                    $options = Category::getPluck();
                    $form->select('category_id','商品分类')->options($options)->required();
                    $form->text('name')->required();
                    $form->currency('price')->symbol("￥")->required();
//                    $form->decimal("city_rate0","无区代理的市代理分成比例(%)")->default(0);
//                    $form->decimal("city_rate1","有区代理的市代理分成比例(%)")->default(0);
//                    $form->decimal("district_rate","区代理的分成比例(%)")->default(0);
//                    $form->decimal("shop_rate","门店分成比例(%)")->default(0);
//                    $form->decimal("user_rate","上级用户分销比例(%)")->default(0);
                    $form->radio('status')->options(['上架','下架'])->default(0);
                });
                $form->column(7,function (Form $form){
                    $form->image('image')->uniqueName()->help("尺寸:169*169")->autoUpload()->autoSave(false)->required();
                    $form->multipleImage('images')->uniqueName()->help("尺寸:375*287")->autoUpload()->autoSave(false)->required();
                });
            });
            $form->tab("商品介绍",function (Form $form){
                $form->ckeditor('content')->required();
            });
        });
    }
}
